import React, { Component } from 'react'
import styles from './SiderMenu.less'
import router from 'umi/router';
import Link from 'umi/link'
import logo from '../assets/global/logo.png'
import Authorized, { havePermission, haveAnyPermission } from '@/utils/Authorized';
import {
  Layout, Menu, Icon,
} from 'antd';

export default class SiderMenu extends Component {

    render() {
        return (
            <Layout.Sider
                className = {styles.leftMenu}
                collapsed = {this.props.collapsed}> 
                {/* 公司logo */}
                <div className = {styles.logo} id="logo">
                    <Link to="/">
                    <img src={logo} alt="logo" />
                    <h1>短信管理平台</h1>
                    </Link>
                </div>
                {/* 左侧菜单项 */}
                <Menu
                    className={styles.menu}
                    defaultSelectedKeys={['1']} //初始化选中
                    defaultOpenKeys={['sub1']}  //初始化展开
                    mode='inline'     //展开样式
                    theme='dark'      //主题颜色样式
                    >
                    <Menu.SubMenu 
                        title = {
                        <span>
                        <Icon type="message" />
                        <span>短信</span>
                        </span>
                    }>
                        <Menu.Item onClick = {(a)=>{
                            router.push("/sms/sendSms")
                        }}><Icon type="mail" />短信发送</Menu.Item>
                        <Menu.Item onClick = {(a)=>{
                            router.push("/sms/smsRecord")
                        }}><Icon type="inbox" />我的短信发送记录</Menu.Item>
                        <Menu.Item onClick = {(a)=>{
                            router.push("/sms/groupSending")
                        }}><Icon type="inbox" />群发管理</Menu.Item>
                        <Menu.Item onClick = {(a)=>{
                            router.push("/sms/smsReply")
                        }}><Icon type="inbox" />平台接收短信</Menu.Item>
                        {Authorized.check(havePermission("AUTH_SMSRECORD_SEL"),
                            <Menu.Item onClick = {(a)=>{
                                router.push("/sms/smsRecordAdmin")
                        }}><Icon type="inbox" />全部短信发送记录</Menu.Item>, null)}
                    </Menu.SubMenu>
                    <Menu.SubMenu 
                        title = {
                        <span>
                        <Icon type="solution" />
                        <span>电话簿</span>
                        </span>
                    }>
                        <Menu.Item onClick = {(a)=>{
                            router.push("/telbook/personal")
                        }}><Icon type="user" />个人电话簿</Menu.Item>
                        {Authorized.check(havePermission("AUTH_SMSTELBOOKE_SEL"),
                            <Menu.Item onClick = {(a)=>{
                                router.push("/telbook/enterprise")
                        }}><Icon type="team" />企业电话簿</Menu.Item>, null)}
                    </Menu.SubMenu>
                    {Authorized.check(haveAnyPermission(["AUTH_SMSUSER_SEL", "AUTH_SMSROLE_SEL"]),
                        <Menu.SubMenu 
                            title = {
                            <span>
                            <Icon type="user" />
                            <span>用户</span>
                            </span>
                        }>  
                            {Authorized.check(havePermission("AUTH_SMSUSER_SEL"),
                                <Menu.Item onClick = {(a)=>{
                                    router.push("/auth/userManager")
                            }}><Icon type="user-add" />用户管理</Menu.Item> , null)}
                            {Authorized.check(havePermission("AUTH_SMSROLE_SEL"),
                                <Menu.Item onClick = {(a)=>{
                                    router.push("/auth/roleManager")
                            }}><Icon type="idcard" />角色管理</Menu.Item> , null)}
                    </Menu.SubMenu>, null)}
                    <Menu.SubMenu 
                        title = {
                        <span>
                        <Icon type="setting" />
                        <span>设置</span>
                        </span>
                    }>
                        <Menu.Item onClick = {(a)=>{
                            router.push("/system/keyt")
                        }}><Icon type="highlight" />短信API</Menu.Item>
                        {Authorized.check(havePermission("AUTH_SETTING_ALL"),
                        <Menu.Item onClick = {(a)=>{
                            router.push("/system/setting")
                        }}><Icon type="desktop" />网关设置</Menu.Item>, null)}
                        {Authorized.check(havePermission("AUTH_SMSSETTING_ALL"),
                        <Menu.Item onClick = {(a)=>{
                            router.push("/system/smsSetting")
                        }}><Icon type="desktop" />平台设置</Menu.Item>, null)}
                    </Menu.SubMenu>
                    <Menu.SubMenu
                        title = {
                        <span>
                        <Icon type="team" />
                        <span>测试</span>
                        </span>
                    }>
                        <Menu.SubMenu 
                        title = {
                            <span>
                            <Icon type="user" />
                            <span>权限测试</span>
                            </span>
                        }>
                        <Menu.Item onClick ={(a)=>{
                            router.push("/test/authority/test1")
                        }}>测试页面1</Menu.Item>
                        <Menu.Item onClick ={(a)=>{
                            router.push("/test/authority/test2")
                        }}>测试页面2</Menu.Item>
                        <Menu.Item onClick ={(a)=>{
                            router.push("/test/authority/test3")
                        }}>测试页面3</Menu.Item>
                        </Menu.SubMenu>
                    </Menu.SubMenu>

                </Menu>
            </Layout.Sider>
        )
    }
}
